home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11510 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Q:  gets, getch, and stdin
  5. Date: 24 Mar 1996 12:50:19 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4j4cibINNgaf@keats.ugrad.cs.ubc.ca>
  8. References: <DnoC9w.Eq9@info.uucp> <31503557.2A97@willows.com>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <31503557.2A97@willows.com>,
  12. Tarang Deshpande  <tarang@willows.com> wrote:
  13.  >Chris Redekop u wrote:
  14.  >> 
  15.  >> 
  16.  >> while ((ch = getch()) != '\r')
  17.  >>         ;
  18.  >> 
  19.  >> while ((ch = getchar()) != '\n')
  20.  >>         ;
  21.  >
  22.  >The reason the \n works and \r does not is because \r means carriage
  23.  >return whereas \n mean new line.  \n means new line reguardless of
  24.  
  25. Not to mention that getch() is not a standard C function whereas getchar() is. 
  26.  
  27.  >what OS your using.  Some OS use <CR><LF> combination for \n other
  28.  
  29. That may be true for streams open in text mode.
  30.  
  31.  >use only <LF> and so on.  So \r does not necessarily mean end of line,
  32.  >where as \n does.
  33.  
  34. You are completely false. The constant '\n' codes for exactly one character,
  35. not two. It cannot represent a CR/LF combination. It only means ``end of line''
  36. in the context of the standard input and output library.
  37.  
  38. I think what you are trying to say is that the standard I/O functions will
  39. convert what is a CR/LF pair at the OS or hardware level to and from a '\n'
  40. character on output and input respectively.
  41.  
  42. If you open a file in binary mode, no such translation should take place, hence
  43. '\n' doesn't intrinsically _mean_ ``end of line''.  
  44.  
  45. In fact, on ascii-based implementations, an untranslated  '\n' typically
  46. corresponds to the ascii LF (character 10) and '\r' is character 13, CR.
  47.  
  48.  
  49. -- 
  50.  
  51.